//
//  ReadEvaluationViewController.m
//  MM
//
//  Created by 郑渊文 on 6/3/15.
//  Copyright (c) 2015 王晨辉. All rights reserved.
//

#import "ReadEvaluationViewController.h"
#import "EvaluateCell.h"
#import "EvaluateModel.h"
#import "EvaluateCellFrame.h"

static NSString *identifier = @"EvaluationCell";
@interface ReadEvaluationViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UIButton *backBtn;
    NSMutableArray *evaluatesList;//评论列表
}
@property(nonatomic,copy)UITableView *myTable;
@property(nonatomic,copy)NSMutableArray *userArray;
@property(nonatomic,copy)NSMutableArray *timeArray;
@property(nonatomic,copy)NSMutableArray *evaluationArray;
@property(nonatomic,copy)NSMutableArray *scoreArray;


@end

@implementation ReadEvaluationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    ////NSLog(@"%@ 什么鬼",_classId);
    evaluatesList = [NSMutableArray array];
    NSDictionary *param4 = @{@"classId":@"1"};
    
    [UserDAL getReadEvaluationParams:param4 withBlock:^(NSDictionary *data, NSError *error) {
        if (data) {
            
        NSArray *array =data[@"dataList"];
        if (array.count == 0) {
            [self ShowProgressHUDwithMessage:@"没有更多评论了！"];
        }
        else
        {
            for (NSDictionary *dict in array)
            {
                 ////NSLog(@"==================%@",dict);
                EvaluateModel *model = [[EvaluateModel alloc] initWithDict:dict];
                EvaluateCellFrame *frame =[[EvaluateCellFrame alloc] init];
                frame.evaluateModel = model;
                [evaluatesList addObject:frame];
               
                //                        [self.tableView beginUpdates];
                //                        int newRowIndex = [evaluatesList count];
                //                        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRowIndex-1<0?newRowIndex:newRowIndex-1 inSection:0];
                //                        [self.tableView insertRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
                //                        [self.tableView endUpdates];
            }
             [_myTable reloadData];
            
             ////NSLog(@"===tamade====================%d",evaluatesList.count);
        }
           
    
        }else
        {}
    }
     ];

     _userArray = [NSMutableArray arrayWithObjects:@"李铁单",@"王二麻",@"郑帅哥",@"张三",@"李四", nil];
    _timeArray = [NSMutableArray arrayWithObjects:@"2015-5-12 9:00",@"2015-5-12 9:00",@"2015-5-12 9:00",@"2015-5-12 9:00",@"2015-5-12 9:00", nil];
    _evaluationArray = [NSMutableArray arrayWithObjects:@"Acting as if nothing borne in mind is the best revenge.It's all for myself to live better.Every day may not be good…but there's something good in every day.Happiness is about having each tiny wish come ture.A woman has got to love a bad man once or twice in her life to be thankful for a good one.",@"Acting as if nothing borne in mind is the best revenge.It's all for myself to live better.Every day may not be good…but there's something good in every day.Happiness is about having each tiny wish come ture.A woman has got to love a bad man once or twice in her life to be thankful for a good one.",@"Acting as if nothing borne in mind is the best revenge.It's all for myself to live better.Every day may not be good…but there's something good in every day.Happiness is about having each tiny wish come ture.A woman has got to love a bad man once or twice in her life to be thankful for a good one.",@"Acting as if nothing borne in mind is the best revenge.It's all for myself to live better.Every day may not be good…but there's something good in every day.Happiness is about having each tiny wish come ture.A woman has got to love a bad man once or twice in her life to be thankful for a good one.",@"Acting as if nothing borne in mind is the best revenge.It's all for myself to live better.Every day may not be good…but there's something good in every day.Happiness is about having each tiny wish come ture.A woman has got to love a bad man once or twice in her life to be thankful for a good one.", nil];
    _scoreArray = [NSMutableArray arrayWithObjects:@"3",@"2",@"1",@"3",@"3", nil];

    [self initSubViews];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

     - (void)ShowProgressHUDwithMessage:(NSString *)msg
    {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
        hud.mode = MBProgressHUDModeText;
        hud.labelText = msg;
        hud.dimBackground = NO;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
    }

-(void)initSubViews
{
    //自定义左右按钮
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
     
                      forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(back)
     
     forControlEvents:UIControlEventTouchUpInside];
    
    button.frame = CGRectMake(0, 0, 20, 15);
    
    
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    
    
    self.navigationItem.leftBarButtonItem = menuButton;
    
    self.navigationItem.title = @"课程评价";
    [self.navigationController.navigationBar setTranslucent:NO];//设置navigationbar的半透明
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#34bd81" alpha:1]];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];

    self.view.backgroundColor = [UIColor clearColor];

    _myTable = [[UITableView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
    _myTable.delegate = self;
    _myTable.dataSource = self;
    [self.view addSubview:_myTable];

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return evaluatesList.count;
   
}


#pragma mark--- tableViewDelegate 区尾的高度

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 1;
    
}

#pragma mark--- tableViewDelegate cell的高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    EvaluateCellFrame *frame = evaluatesList[indexPath.row];
    return frame.cellHeight;
    
}
#pragma mark--- tableViewDelegate cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    static NSString *NOTIFY = @"cell";
//    EvaluateCell *cell = (EvaluateCell *)[tableView dequeueReusableCellWithIdentifier:NOTIFY];
//    if (cell==nil) {
//        cell=[[EvaluateCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NOTIFY];
//    }
//    cell.evaluateUser.text = _userArray[indexPath.row];
//    ////NSLog(@"是个什么鬼啊%@",cell.evaluateUser.text);
//    cell.evaluateContent.text = _evaluationArray[indexPath.row];
//    cell.evaluateTime.text = _timeArray[indexPath.row];
//    cell.score = [_scoreArray[indexPath.row]intValue];
////    numberOfStar= [_scoreArray[indexPath.row]intValue];
    
    EvaluateCell *cell = (EvaluateCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil)
    {
        cell = [[EvaluateCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.myEvaluateCellFrame = evaluatesList[indexPath.row];
    return cell;

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

-(void)back
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}


@end
